﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using iTextSharp.text;
using System.IO;
using iTextSharp.text.html.simpleparser;
using iTextSharp.text.pdf;
using System.Data;
using System.Data.SqlClient;

namespace QLBV
{
    public partial class testExport : System.Web.UI.Page
    {
        SqlConnection conn;
        String strCon = "Data Source=HTD-COM;Initial Catalog=QLBV;Integrated Security=True;Pooling=False";
        protected void Page_Load(object sender, EventArgs e)
        {
            //get Bac si
            String maBS = Session["User"].ToString();
            string strDonThuoc = "Select * from Users Where Username='" + maBS + "'";
            conn = new SqlConnection(strCon);
            conn.Open();
            DataSet ds = new DataSet();
            SqlDataAdapter da = new SqlDataAdapter(strDonThuoc, conn);
            da.Fill(ds, "Users");
            //get Session
            lbBS.Text = ds.Tables["Users"].Rows[0][3].ToString();
            lbName.Text = Session["name"].ToString();
            lbGender.Text = Session["gender"].ToString();
            lbCanBenh.Text=Session["canbenh"].ToString();
            String maBN=Session["maBN"].ToString();
            //fill gridview
            String strSelect = "SELECT TenThuoc,NgayUong,LanUong,DonVi FROM DonThuoc where MaBN='" + maBN + "'";
            conn = new SqlConnection(strCon);
            conn.Open();
            SqlDataAdapter adapter = new SqlDataAdapter(strSelect, conn);
            DataTable dt = new DataTable();
            adapter.Fill(dt);
            gvXuat.DataSource = dt;
            gvXuat.DataBind();
            conn.Close();
            lbDate0.Text = DateTime.Now.Date.ToString();
        }
     
    
        protected void Button1_Click1(object sender, EventArgs e)
        {
            Response.ContentType = "application/pdf";
            Response.AddHeader("content-disposition", "attachment;filename=Panel.pdf");
            Response.Cache.SetCacheability(HttpCacheability.NoCache);
            StringWriter sw = new StringWriter();
            HtmlTextWriter hw = new HtmlTextWriter(sw);
            text.RenderControl(hw);
            StringReader sr = new StringReader(sw.ToString());
            Document pdfDoc = new Document(PageSize.A4, 10f, 10f, 100f, 0f);
            HTMLWorker htmlparser = new HTMLWorker(pdfDoc);
            PdfWriter.GetInstance(pdfDoc, Response.OutputStream);
            pdfDoc.Open();
            htmlparser.Parse(sr);
            pdfDoc.Close();
            Response.Write(pdfDoc);
            Response.End();
        }

        
    }
}